<!DOCTYPE html>


<html lang="zn-CH">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="What I can do is to Do My Personal Best!" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    java整合七牛云,实现资源管理 |  小熊的博客
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="http://www.cdn.adingxiong.com/b5363a06dc744d79a94021492bcefe27" />
  
  
<link rel="stylesheet" href="/blog/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/blog/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/blog/atom.xml" title="小熊的博客" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content on">
      <section class="outer">
  <article id="post-java整合七牛云-实现资源管理" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  java整合七牛云,实现资源管理
</h1>
 

    </header>
    

    
    <div class="article-meta">
      <a href="/blog/2020/09/04/java%E6%95%B4%E5%90%88%E4%B8%83%E7%89%9B%E4%BA%91-%E5%AE%9E%E7%8E%B0%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86/" class="article-date">
  <time datetime="2020-09-04T08:25:40.000Z" itemprop="datePublished">2020-09-04</time>
</a>
      
      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">1.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">8 min</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      
      

      
      <p><a href="https://developer.qiniu.com/kodo/sdk/1239/java" target="_blank" rel="noopener">官方SDK地址(java自取)</a></p>
<h3 id="依赖下载"><a href="#依赖下载" class="headerlink" title="依赖下载"></a>依赖下载</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--七牛云图片上传--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.qiniu<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>qiniu-java-sdk<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>[7.2.0, 7.2.99]<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!--        七牛云sdk相关依赖--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.squareup.okhttp3<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>okhttp<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.14.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>compile<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.google.code.gson<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>gson<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.8.5<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>compile<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.qiniu<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>happy-dns-java<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.1.6<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>


<h3 id="代码整合"><a href="#代码整合" class="headerlink" title="代码整合"></a>代码整合</h3><p>七牛云相关属性配置,直接写在<code>application.yml</code>中</p>
<p><img src="https://user-gold-cdn.xitu.io/2020/7/17/1735bc9bff4c4bd1?w=1784&h=548&f=png&s=83375" alt></p>
<p><img src="https://user-gold-cdn.xitu.io/2020/7/17/1735bcab3e7d77ac?w=740&h=702&f=png&s=51711" alt></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">qiniu:</span></span><br><span class="line">  <span class="attr">accesskey:</span> <span class="string">xxxxxxxxxxxxxxxx</span></span><br><span class="line">  <span class="attr">secretkey:</span> <span class="string">xxxxxxxxxxxxxxxx</span></span><br><span class="line">  <span class="comment">#空间名</span></span><br><span class="line">  <span class="attr">bucket:</span> <span class="string">admin</span></span><br><span class="line">  <span class="comment"># 加速域名</span></span><br><span class="line">  <span class="attr">domain:</span> <span class="string">cdn.nihao.com</span></span><br></pre></td></tr></table></figure>

<p><a href="https://juejin.im/post/6850418121569009672" target="_blank" rel="noopener">配置参数读取方式参考</a></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.adingxiong.pm.controller;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.adingxiong.pm.entity.vo.ImageListVo;</span><br><span class="line"><span class="keyword">import</span> com.adingxiong.pm.model.Result;</span><br><span class="line"><span class="keyword">import</span> com.adingxiong.pm.model.RetCode;</span><br><span class="line"><span class="keyword">import</span> com.adingxiong.pm.util.UploadUtils;</span><br><span class="line"><span class="keyword">import</span> com.google.gson.Gson;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.common.QiniuException;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.http.Response;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.BucketManager;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.Configuration;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.Region;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.UploadManager;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.model.BatchStatus;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.model.DefaultPutRet;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.qiniu.storage.model.FileInfo;</span><br><span class="line"><span class="keyword">import</span> com.qiniu.util.Auth;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.Api;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiImplicitParam;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiImplicitParams;</span><br><span class="line"><span class="keyword">import</span> io.swagger.annotations.ApiOperation;</span><br><span class="line"><span class="keyword">import</span> org.springframework.beans.factory.annotation.Value;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestMethod;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RequestParam;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.bind.annotation.RestController;</span><br><span class="line"><span class="keyword">import</span> org.springframework.web.multipart.MultipartFile;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> javax.servlet.http.HttpServletRequest;</span><br><span class="line"><span class="keyword">import</span> java.io.File;</span><br><span class="line"><span class="keyword">import</span> java.io.IOException;</span><br><span class="line"><span class="keyword">import</span> java.text.SimpleDateFormat;</span><br><span class="line"><span class="keyword">import</span> java.util.*;</span><br><span class="line"><span class="keyword">import</span> java.util.stream.Collectors;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 七牛云图片上传</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@RestController</span></span><br><span class="line"><span class="meta">@RequestMapping</span>(<span class="string">"/img"</span>)</span><br><span class="line"><span class="meta">@Api</span>(tags = <span class="string">"资源管理"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ImageUploadController</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> QiniuConfiguration config;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">private</span> String accesskey = config.getAccesskey();</span><br><span class="line">    <span class="keyword">private</span> String secretKey = config.getSecretKey();</span><br><span class="line">    <span class="keyword">private</span> String bucket = config.getBucket();</span><br><span class="line">    <span class="keyword">private</span> String bucket = config.getBucket();</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"获取图片上传的Token"</span>)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/getUploadToken"</span>, method = RequestMethod.GET)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">qiniuToken</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//验证七牛云身份是否认证通过</span></span><br><span class="line">            Auth auth = Auth.create(accesskey, secretKey);</span><br><span class="line">            <span class="comment">//生成上传凭证</span></span><br><span class="line">            String token = auth.uploadToken(bucket);</span><br><span class="line"></span><br><span class="line">            Map&lt;String, String&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line">            map.put(<span class="string">"upToken"</span>, token);</span><br><span class="line">            map.put(<span class="string">"domain"</span>, domain);</span><br><span class="line">            String randomFile = UUID.randomUUID().toString();</span><br><span class="line">            map.put(<span class="string">"imgUrl"</span>, randomFile);</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"获取token成功"</span>).setData(map);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result().setMsg(e.toString()).setCode(RetCode.FAIL).setMsg(<span class="string">"获取token失败"</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"上传资源至指定七牛云服务器"</span>)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/uploadResource"</span>, method = RequestMethod.POST)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">uploadResource</span><span class="params">(@RequestParam(<span class="string">"file"</span>)</span> MultipartFile file) </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//构造一个带指定 Region 对象的配置类</span></span><br><span class="line">        Configuration cfg = <span class="keyword">new</span> Configuration(Region.region0());</span><br><span class="line">        <span class="comment">//...其他参数参考类注释</span></span><br><span class="line"></span><br><span class="line">        UploadManager uploadManager = <span class="keyword">new</span> UploadManager(cfg);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//如果是Windows情况下，格式是 D:\\qiniu\\test.png</span></span><br><span class="line">        <span class="comment">//String localFilePath = "D:\\qiniu\\4.png";</span></span><br><span class="line">        <span class="comment">//默认不指定key的情况下，以文件内容的hash值作为文件名</span></span><br><span class="line">        String key = UUID.randomUUID().toString().replaceAll(<span class="string">"-"</span>, <span class="string">""</span>);</span><br><span class="line"></span><br><span class="line">        Auth auth = Auth.create(accesskey, secretKey);</span><br><span class="line">        String upToken = auth.uploadToken(bucket);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="keyword">byte</span>[] byteInputStream = file.getBytes();</span><br><span class="line">            Response response = uploadManager.put(byteInputStream, key, upToken);</span><br><span class="line">            <span class="comment">//解析上传成功的结果</span></span><br><span class="line">            DefaultPutRet putRet = <span class="keyword">new</span> Gson().fromJson(response.bodyString(), DefaultPutRet<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"资源上传成功"</span>).setData(putRet);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (QiniuException ex) &#123;</span><br><span class="line">            Response r = ex.response;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(r.toString());</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(e.toString());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"获取七牛云空间中的列表信息"</span>)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/getQiniuList"</span>, method = RequestMethod.GET)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">getQiniuList</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">//构造一个带指定 Region 对象的配置类</span></span><br><span class="line">        Configuration cfg = <span class="keyword">new</span> Configuration(Region.region0());</span><br><span class="line">        <span class="comment">//...其他参数参考类注释</span></span><br><span class="line">        Auth auth = Auth.create(accesskey, secretKey);</span><br><span class="line">        BucketManager bucketManager = <span class="keyword">new</span> BucketManager(auth, cfg);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//文件名前缀</span></span><br><span class="line">        String prefix = <span class="string">""</span>;</span><br><span class="line">        <span class="comment">//每次迭代的长度限制，最大1000，推荐值 1000</span></span><br><span class="line">        <span class="keyword">int</span> limit = <span class="number">1000</span>;</span><br><span class="line">        <span class="comment">//指定目录分隔符，列出所有公共前缀（模拟列出目录效果）。缺省值为空字符串</span></span><br><span class="line">        String delimiter = <span class="string">""</span>;</span><br><span class="line"></span><br><span class="line">        SimpleDateFormat sdf = <span class="keyword">new</span> SimpleDateFormat(<span class="string">"yyyy-MM-dd HH:mm:ss"</span>);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//列举空间文件列表</span></span><br><span class="line">        BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, prefix, limit, delimiter);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        List&lt;ImageListVo&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="keyword">while</span> (fileListIterator.hasNext()) &#123;</span><br><span class="line">            <span class="comment">//处理获取的file list结果</span></span><br><span class="line">            FileInfo[] items = fileListIterator.next();</span><br><span class="line"></span><br><span class="line">            <span class="keyword">for</span>(FileInfo info :items)&#123;</span><br><span class="line">                ImageListVo vo = <span class="keyword">new</span> ImageListVo();</span><br><span class="line">                vo.setEndUser(info.endUser);</span><br><span class="line">                vo.setFsize(info.fsize);</span><br><span class="line">                vo.setHash(info.hash);</span><br><span class="line">                vo.setMineType(info.mimeType);</span><br><span class="line">                vo.setKey(info.key);</span><br><span class="line"></span><br><span class="line">                String time = info.putTime  + <span class="string">""</span>;</span><br><span class="line">                time = time.substring(<span class="number">0</span>,<span class="number">13</span>);</span><br><span class="line">                vo.setPutTime(sdf.format(<span class="keyword">new</span> Date(Long.parseLong(time))));</span><br><span class="line">                list.add(vo);</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"获取资源列表成功"</span>).setData(list);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"批量删除文件（key，type）"</span>)</span><br><span class="line">    <span class="meta">@ApiImplicitParams</span>(&#123;</span><br><span class="line">            <span class="meta">@ApiImplicitParam</span>(name = <span class="string">"keys"</span>, value = <span class="string">"需要删除的所有keys"</span>, paramType = <span class="string">"query"</span>, dataType = <span class="string">"Array"</span>)</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/deletImg"</span>, method = RequestMethod.GET)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">deletImg</span><span class="params">(String[] keys)</span> </span>&#123;</span><br><span class="line">        <span class="comment">//构造一个带指定 Region 对象的配置类</span></span><br><span class="line">        Configuration cfg = <span class="keyword">new</span> Configuration(Region.region0());</span><br><span class="line">        <span class="comment">//...其他参数参考类注释</span></span><br><span class="line">        Auth auth = Auth.create(accesskey, secretKey);</span><br><span class="line">        BucketManager bucketManager = <span class="keyword">new</span> BucketManager(auth, cfg);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            BucketManager.BatchOperations batchOperations = <span class="keyword">new</span> BucketManager.BatchOperations();</span><br><span class="line">            batchOperations.addDeleteOp(bucket, keys);</span><br><span class="line">            Response response = bucketManager.batch(batchOperations);</span><br><span class="line">            BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[]<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; keys.length; i++) &#123;</span><br><span class="line">                BatchStatus status = batchStatusList[i];</span><br><span class="line">                String key = keys[i];</span><br><span class="line">                System.out.print(key + <span class="string">"\t"</span>);</span><br><span class="line">                <span class="keyword">if</span> (status.code != <span class="number">200</span>) &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(status.data.error);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"删除成功"</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (QiniuException ex) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.INTERNAL_SERVER_ERROR).setMsg(ex.response.toString());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"文件重命名"</span>)</span><br><span class="line">    <span class="meta">@ApiImplicitParams</span>(&#123;</span><br><span class="line">            <span class="meta">@ApiImplicitParam</span>(name = <span class="string">"key"</span>, value = <span class="string">"文件key"</span>, paramType = <span class="string">"query"</span>, dataType = <span class="string">"String"</span>),</span><br><span class="line">            <span class="meta">@ApiImplicitParam</span>(name = <span class="string">"newName"</span>, value = <span class="string">"新的文件名"</span>, paramType = <span class="string">"query"</span>, dataType = <span class="string">"Array"</span>),</span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/rename"</span>, method = RequestMethod.GET)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">rename</span><span class="params">(String[] keyList, String newName)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        Configuration cfg = <span class="keyword">new</span> Configuration(Region.region0());</span><br><span class="line">        <span class="comment">//...其他参数参考类注释</span></span><br><span class="line">        Auth auth = Auth.create(accesskey, secretKey);</span><br><span class="line">        BucketManager bucketManager = <span class="keyword">new</span> BucketManager(auth, cfg);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            BucketManager.BatchOperations batchOperations = <span class="keyword">new</span> BucketManager.BatchOperations();</span><br><span class="line">            <span class="keyword">for</span> (String key : keyList) &#123;</span><br><span class="line">                batchOperations.addMoveOp(bucket, key, bucket, newName);</span><br><span class="line">            &#125;</span><br><span class="line">            Response response = bucketManager.batch(batchOperations);</span><br><span class="line">            BatchStatus[] batchStatusList = response.jsonToObject(BatchStatus[]<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; keyList.length; i++) &#123;</span><br><span class="line">                BatchStatus status = batchStatusList[i];</span><br><span class="line">                String key = keyList[i];</span><br><span class="line">                <span class="keyword">if</span> (status.code != <span class="number">200</span>) &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(status.data.error);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"修改完成"</span>);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (QiniuException ex) &#123;</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.INTERNAL_SERVER_ERROR).setMsg(ex.response.toString());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Value</span>(value = <span class="string">"$&#123;file.location.path&#125;"</span>)</span><br><span class="line">    <span class="keyword">private</span> String savePath;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@ApiOperation</span>(value = <span class="string">"本地资源上传"</span>)</span><br><span class="line">    <span class="meta">@RequestMapping</span>(value = <span class="string">"/uploadlocal"</span>, method = RequestMethod.POST)</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Result <span class="title">uploadImg</span><span class="params">(@RequestParam MultipartFile file, HttpServletRequest request)</span> <span class="keyword">throws</span> IOException </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (file != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">double</span> size = file.getSize();</span><br><span class="line">            <span class="keyword">byte</span>[] sizebyte = file.getBytes();</span><br><span class="line"></span><br><span class="line">            String filename = file.getOriginalFilename();</span><br><span class="line">            String type = filename.indexOf(<span class="string">"."</span>) != -<span class="number">1</span> ? filename.substring(filename.lastIndexOf(<span class="string">"."</span>) + <span class="number">1</span>, filename.length()) : <span class="keyword">null</span>;</span><br><span class="line">            <span class="keyword">if</span> (type != <span class="keyword">null</span>) &#123;</span><br><span class="line">                <span class="keyword">if</span> (<span class="string">"GIF"</span>.equals(type.toUpperCase()) || <span class="string">"PNG"</span>.equals(type.toUpperCase()) || <span class="string">"JPG"</span>.equals(type.toUpperCase()) || <span class="string">"JPEG"</span>.equals(type.toUpperCase())) &#123;</span><br><span class="line"></span><br><span class="line">                    String url = UploadUtils.upload(file, <span class="string">"/upload"</span>, savePath);</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.SUCCESS).setMsg(<span class="string">"上传成功"</span>).setData(url);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(<span class="string">"类型不支持"</span>);</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Result&lt;&gt;().setCode(RetCode.FAIL).setMsg(<span class="string">"上传文件为空"</span>);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>




      
      <!-- reward -->
      
      <div id="reward-btn">
        Donate
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>Copyright： </strong>
              Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://bodboy.gitee.io/blog/2020/09/04/java%E6%95%B4%E5%90%88%E4%B8%83%E7%89%9B%E4%BA%91-%E5%AE%9E%E7%8E%B0%E8%B5%84%E6%BA%90%E7%AE%A1%E7%90%86/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/qiniu/" rel="tag">qiniu</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/blog/2020/09/04/%E8%87%AA%E5%AE%9A%E4%B9%89%E9%85%8D%E7%BD%AE%E7%B1%BB%EF%BC%8C%E8%AF%BB%E5%8F%96Application-properties%E4%B8%AD%E7%9A%84%E5%8F%82%E6%95%B0/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            自定义配置类，读取Application.properties中的参数
          
        </div>
      </a>
    
    
      <a href="/blog/2020/09/04/%E8%8E%B7%E5%8F%96%E6%8C%87%E5%AE%9A%E6%9C%88%E4%BB%BD%E7%9A%84%E6%89%80%E6%9C%89%E5%B7%A5%E4%BD%9C%E6%97%A5-%E5%B7%A5%E4%BD%9C%E6%97%A5%E4%B8%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">获取指定月份的所有工作日(工作日为自定义的)</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'uW8QYGvvhWmNWdiwpznJ0GVa-gzGzoHsz',
        app_key: 'LrJhMzx9qEwcMV1DJjTI6f6C',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: '[object Object]',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2019-2021
        <i class="ri-heart-fill heart_icon"></i> panda
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/blog/"><img src="https://portrait.gitee.com/uploads/avatars/user/1007/3023420_bodboy_1578973210.png!avatar200" alt="小熊的博客"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/tags/%E6%97%85%E8%A1%8C/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/blog/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/blog/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/blog/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/blog/js/jquery-2.0.3.min.js"></script>


<script src="/blog/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/blog/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/blog/dist/main.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>




<script src="/blog/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>

  
<script src="/blog/js/clickLove.js"></script>



<!-- 复制 -->



    
    <div id="music">
    
    
    
    <iframe frameborder="no" border="1" marginwidth="0" marginheight="0" width="200" height="52"
        src="//music.163.com/outchain/player?type=2&id=1297802566&auto=1&height=32"></iframe>
</div>

<style>
    #music {
        position: fixed;
        right: 15px;
        bottom: 0;
        z-index: 998;
    }
</style>
    
  </div>
</body>

</html>